package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.CastleTable;
import com.lineage.server.datatables.storage.CastleStorage;
import com.lineage.server.templates.L1Castle;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CastleReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final CastleStorage _storage = (CastleStorage)new CastleTable();
  
  private static CastleReading _instance;
  
  public static CastleReading get() {
    if (_instance == null)
      _instance = new CastleReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public Map<Integer, L1Castle> getCastleMap() {
    Map<Integer, L1Castle> tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getCastleMap();
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1Castle[] getCastleTableList() {
    L1Castle[] tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getCastleTableList();
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1Castle getCastleTable(int id) {
    L1Castle tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getCastleTable(id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void updateCastle(L1Castle castle) {
    this._lock.lock();
    try {
      this._storage.updateCastle(castle);
    } finally {
      this._lock.unlock();
    } 
  }
}
